//
//  WebGetUserInfoToHttp.m
//  OMS
//
//  Created by goldeney on 14/11/14.
//  Copyright (c) 2014年 ShangHai Goldeneye Techonology Co.,Ltd. All rights reserved.
//

#import "WebGetUserInfoToHttp.h"
#import "NSKeyedArchiverUserLogin.h"
#import "AESCrypt.h"

@implementation WebGetUserInfoToHttp

+ (NSString*)getUserInfoToJSON
{
    //传递用户信息
    UserLoginNSCoding *userInfo = [NSKeyedArchiverUserLogin getUserLoginData];
    if(!userInfo) return nil;
    
    NSString *sessionValue = [self dictionaryToJson:[userInfo dictionary]];
    NSString *AESsession = [AESCrypt encrypt:sessionValue];
    
    NSString *replacString01 = [AESsession stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
    NSString *replacString02 = [replacString01 stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
    
    return replacString02;
}

//字典转Json
+ (NSString*)dictionaryToJson:(NSDictionary *)dic
{
    NSError *parseError = nil;
    NSData  *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

@end
